﻿using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using web01.Models;
using web01.Models.DO;

namespace web01.Controllers
{
    public class EfController:Controller
    {

        private MyDbContext MyDbContext;
        public EfController(MyDbContext myDbContext)
        {
            MyDbContext = myDbContext;
        }

        public IActionResult Index()
        {
            var a = new { a="张三" };

            var personsList = MyDbContext.persons.ToList();

            /*ViewBag.person = personsList;*/
            return View(personsList);
        }
        
        [HttpPost]
        public async Task<ResultModel<string>> AddUser([FromBody]Persons users)
        {
            var resultModel = new ResultModel<string>();
            var a = Request.Body.ToString();
            //var entityEntry = MyDbContext.persons.Add(users);
            resultModel.Success = true;
            resultModel.ResultMsg = "添加成功！";
            return resultModel;
        }
    }
}